<template>
  <div>
    <div class="parent">
      <!-- 父评论的父评论 -->
      <!-- 2. 根据组件名自己调用自己，如果还有父级评论数据，继续调用自己 -->
      <ContentParent
        v-if="parent.parent"
        :parent="parent.parent"
        @parentReply="reply"
      ></ContentParent>
      <div class="parent-header">
        <span>{{ parent.user.nickname }}</span>
        <span class="date">{{ parent.create_date }}</span>
        <span class="reply" @click="reply(parent)">回复</span>
      </div>
      <div class="parent-body">
        {{ parent.content }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  // 1. 给组件自己起个名字
  name: "ContentParent",
  props: {
    parent: Object,
  },
  methods: {
    reply(parent) {
      // console.log(parent);
      this.$emit("parentReply", parent);
    },
  },
};
</script>

<style lang="less" scoped>
.parent {
  border: 1px solid #f00;
  padding: 5px;
  .parent-header {
    font-size: 12px;
    color: #999;
    display: flex;
    .date {
      margin-left: 10px;
      flex: 1;
    }
    .reply {
      position: relative;
      z-index: 11;
      color: #f00;
    }
  }
  .parent-body {
    font-size: 14px;
    margin: 5px 0;
  }
}
</style>